﻿
using System;

namespace Red.Core.Math
{
    /// <summary>
    ///     Bunch of methods to work with vectors
    /// </summary>
    public static class VectorHelpers
    {
        /// <summary>
        ///     Calculates angle of 3d vector [x, y] to OX axis
        /// </summary>
        public static float GetAngleToOX( float x, float y )
        {
            const float PI = (float)System.Math.PI;
            const float PI2 = (float)System.Math.PI / 2f;
            if ( x == 0 )
            {
                return y > 0 ? PI2 : 3f * PI2;
            }
            else
            {
                float a = (float)System.Math.Atan2( System.Math.Abs( y ), System.Math.Abs( x ) );
                if ( y > 0 )
                    return x > 0 ? a : PI - a;
                else
                    return x > 0 ? 2f * PI - a : PI + a;
            }
        }
    }
}